define(
		[],
		function() {

			webUtils.nameSpace("wiseMen.platform.roleSelector");

			/*
			 * 组织机构选择组件 onSelect:function(rows){} 选择回调方法 scope:this, 作用域
			 * isSingle:false,是否单选 hasSelectedOrgs:selectedRows,已选择的单位
			 */
			wiseMen.platform.roleSelector.main = function(params) {
				var roleGrid;
				var hasSelectedGrid;
				params = $.extend({
					scope : this,
					hasSelectedRoles : [],
					isSingle : false,
					onSelect : function(rows) {
					}
				}, params);
				var dialog = webUtils.dialog({
							title : '选择角色',
							size : "w",
							onremove : function() {
								if (params.onClose) {
									params.onClose.call(null);
								}
							},
							buttons : [
									{
										label : '关闭',
										action : function(dialog) {
											dialog.close();
										}
									},
									{
										label : '确定',
										icon : 'glyphicon glyphicon-check',
										cssClass : 'btn-primary',
										action : function(dialog) {
											var rows = hasSelectedGrid
													.bootstrapTable("getData");
											params.onSelect.call(params.scope,
													rows);
											dialog.close();
										}
									} ],
							onshown : function(d) {
								var body = d.getModalBody();
								body.append(wiseMen.platform.roleSelector.tpl);
								var mainContent = body.find(".mainContent");

								roleGrid = new wiseMen.platform.roleSelector.roleGrid(
										{
											target : mainContent
													.find("._roleGrid"),
											onSelect : function(row) {
												onSelectRole(row);
											}
										});

								hasSelectedGrid = new wiseMen.platform.roleSelector.hasSelectedGrid(
										{
											target : mainContent
													.find("._hasSelectedBox"),
											hasSelectedRoles : params.hasSelectedRoles
										});
							}
						});

				function onSelectRole(row) {
					var data = hasSelectedGrid.bootstrapTable(
							"getRowByUniqueId", row.id);
					if (!data) {
						if (params.isSingle) {
							hasSelectedGrid.bootstrapTable('removeAll');// 清空下方DateGrid
						}

						hasSelectedGrid.bootstrapTable("append", {
							id : row.id,
							roleName : row.roleName,
							roleKey : row.roleKey
						});
					}
				}
			};

			wiseMen.platform.roleSelector.roleGrid = function(params) {
				params = $.extend({
					scope : this,
					onSelect : function(row) {
					}
				}, params);

				var roleGrid = params.target.bootstrapTable({
					url : ctx + "/roleAction/queryRolesInUser.do",
					queryParams : function(d) {
						if (roleGrid) {
						}
						return d;
					},
					columns : [ {
						field : '_s',
						checkbox : true
					}, {
						title : '角色名称',
						field : 'roleName',
						width : 120,
						filterControl : "input"
					}, {
						title : '标识',
						field : 'roleKey',
						width : 120,
						filterControl : "input"
					} ],
					filterControl : true,
					singleSelect : true,
					height : $(window).height() * 0.7,
					onClickRow : params.onSelect
				});

				return roleGrid;
			}

			wiseMen.platform.roleSelector.hasSelectedGrid = function(params) {
				params = $.extend({
					hasSelectedRoles : null
				}, params);

				var grid = params.target.bootstrapTable({
					columns : [ {
						title : '角色名称',
						field : 'roleName',
						width : 120
					}, {
						title : '标识',
						field : 'roleKey',
						width : 120
					} ],
					sidePagination : 'client',
					pagination : false,
					uniqueId : "id",
					data : params.hasSelectedRoles,
					onClickRow : function(row) {
						grid.bootstrapTable("removeByUniqueId", row.id);
					}
				});
				return grid;
			}

			wiseMen.platform.roleSelector.tpl = '<div class="mainContent row" style="height:100%">'
					+ '<div title="角色列表" class="col-md-6"><table class="_roleGrid"></table></div>'
					+ '<div title="已选列表" class="col-md-6"><table class="_hasSelectedBox"></table></div>'
					+ '</div>';

			return wiseMen.platform.roleSelector.main;
		});
